package com.ericsson.resourceplanner.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ericsson.resourceplanner.dao.ChangeRoleDAO;
import com.ericsson.resourceplanner.dao.entity.EmpDetails;
import com.ericsson.resourceplanner.dao.entity.EmployeeRole;
import com.ericsson.resourceplanner.dao.entity.Role;
import com.ericsson.resourceplanner.dto.EmployeeDtlsVO;
import com.ericsson.resourceplanner.service.ChangeRoleService;


@Service
public class ChangeRoleServiceImpl implements ChangeRoleService {
	
	@Autowired
    ChangeRoleDAO changeRoleDAO;
	
	public ChangeRoleDAO getChangeRoleDAO() {
		return changeRoleDAO;
	}
	public void setChangeRoleDAO(ChangeRoleDAO changeRoleDAO) {
		this.changeRoleDAO = changeRoleDAO;
	}
	public List<EmployeeDtlsVO> getEmpList(){
	List<EmployeeDtlsVO> emplist_vo = new ArrayList<EmployeeDtlsVO>();	
	List<EmpDetails> list=	changeRoleDAO.fetchEmployeeDetails();
	List<Long> role_list = null;
	
	if(list!=null && list.size()>0){
		for(EmpDetails emp:list){
			role_list = new ArrayList<Long>();
			EmployeeDtlsVO  vo = new EmployeeDtlsVO();	
			vo.setEmploye_Name(emp.getEmp_name());
			vo.setId(Integer.valueOf(emp.getiD()));
			vo.setSignum_id(emp.getSignum_id());
			
			for(EmployeeRole er : emp.getEmployeeRoles())
			{
				
				role_list.add(er.getRole().getId());
			}
			vo.setEmp_rolelist(role_list);
			emplist_vo.add(vo);
			
		}
		
		
	}
     return emplist_vo;
	}
	public List<Role> getRoleList(){
	  List<Role> role_list = changeRoleDAO.fetchRoleDetails();
		return role_list;
	}
	@Override
	public void updateRole(EmployeeDtlsVO[] emp) {
		// TODO Auto-generated method stub
		changeRoleDAO.updateRole(emp);
	}

}
